finding minimum cost